package com.example.mydy.model;

import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
import java.util.List;

public class User {
    @SerializedName("id")
    private int id;

    @SerializedName("username")
    private String username;

    @SerializedName("nickname")
    private String nickname;

    @SerializedName("points")
    private int points;

    @SerializedName("level")
    private String level;

    @SerializedName("phone")
    private String phone;

    @SerializedName("balance")
    private double balance;

    @SerializedName("avatar")
    private String avatar;

    @SerializedName("created_at")
    private String createdAt;

    @SerializedName("updated_at")
    private String updatedAt;

    @SerializedName("income_records")
    private List<IncomeRecord> incomeRecords = new ArrayList<>();

    public User() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public int getPoints() {
        return points;
    }

    public void setPoints(int points) {
        this.points = points;
    }

    public String getLevel() {
        return level;
    }

    public void setLevel(String level) {
        this.level = level;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(String createdAt) {
        this.createdAt = createdAt;
    }

    public String getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(String updatedAt) {
        this.updatedAt = updatedAt;
    }

    public List<IncomeRecord> getIncomeRecords() {
        return incomeRecords;
    }

    public void setIncomeRecords(List<IncomeRecord> incomeRecords) {
        this.incomeRecords = incomeRecords;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", nickname='" + nickname + '\'' +
                ", level='" + level + '\'' +
                ", balance=" + balance +
                ", phone='" + phone + '\'' +
                ", points=" + points +
                ", createdAt='" + createdAt + '\'' +
                ", incomeRecords=" + incomeRecords +
                '}';
    }

    // 从UserData对象创建User对象
    public static User fromUserData(UserData userData) {
        User user = new User();
        user.setId(userData.getId());
        user.setUsername(userData.getUsername());
        user.setNickname(userData.getNickname());
        user.setBalance(userData.getBalance());
        user.setLevel(userData.getLevel());
        user.setPoints(userData.getPoints());
        user.setPhone(userData.getPhone());
        user.setCreatedAt(userData.getCreatedAt());
        return user;
    }
}